// 新闻接口服务
const TOKEN = 'ycd0krwbhl5v2w6iafblj94y5vzqdj';
const BASE_URL = 'https://v3.alapi.cn/api';

// 获取新闻类型
export const getNewsTypes = () => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: `${BASE_URL}/new/toutiao/type`,
            method: 'GET',
            data: {
                token: TOKEN
            },
            success: (res) => {
                resolve([null, res]);
            },
            fail: (err) => {
                resolve([err, null]);
            }
        });
    });
};

// 获取新闻列表
export const getNewsList = (type = 1, page = 1) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: `${BASE_URL}/new/toutiao`,
            method: 'GET',
            data: {
                token: TOKEN,
                type: type,
                page: page
            },
            success: (res) => {
                resolve([null, res]);
            },
            fail: (err) => {
                resolve([err, null]);
            }
        });
    });
};